﻿using System;
using System.Data;
using System.Reflection.Emit;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using SoftwareDiscipline.SharePoint.UserManagement.Data;

namespace SoftwareDiscipline.SharePoint.UserManagement.Layouts.SoftwareDiscipline
{
    public partial class AllRoles : LayoutsPageBase, IPostBackEventHandler
    {
       
        protected void Page_Load(object sender, EventArgs e)
        {
            AllRolesDataSource allRolesDataSource = new AllRolesDataSource();

            //SPGridView spGridView = (SPGridView) this.gvAllRoles;

            //DataTable dataTable = new DataTable();
            //DataColumn dataColumn = new DataColumn("RoleName", typeof (string));
            //dataTable.Columns.Add(dataColumn);

            //foreach (string roles in allRolesDataSource.GetAllRoles())
            //{
            //    DataRow row = dataTable.NewRow();
            //    row[0] = roles;
            //    dataTable.Rows.Add(row);
            //}

            //spGridView.DataSource = dataTable;
            //spGridView.DataBind();
            
        }

        void IPostBackEventHandler.RaisePostBackEvent(string eventArgument)
        {
            // check what type of event argument it is
            string[] eventArgs = eventArgument.Split(new Char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            if (eventArgs.Length > 0)
            {
                string operation = eventArgs[0].Trim().ToLower();
                string roleName = eventArgs[1];
                

                if (operation == "delete")
                {
                    AllRolesDataSource allRolesDataSource = new AllRolesDataSource();
                    string Deletestatus=allRolesDataSource.DelteRole(roleName);
                    Response.Redirect("allRoles.aspx");

                }
                if (operation=="users")
                {
                    Response.Redirect("allUsers.aspx?role="+roleName);
                    

                }

            }
        }
    }
}
